<html>
<head><meta charset="utf-8"><title>Resolving result differences · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html">Resolving result differences</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206024096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024096">(Aug 05 2020 at 13:51)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Ms</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">ms</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="bp">Self</span>:<span class="nb">Sized</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Ms</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">ms</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="n">panic</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;1&quot;</span><span class="p">)}}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">Ms</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">i64</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">ms</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="n">panic</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;2&quot;</span><span class="p">)}}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.</span><span class="n">ms</span><span class="p">();</span><span class="w">  </span><span class="c1">// this compiles, defaults to i32.</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.</span><span class="n">abs</span><span class="p">();</span><span class="w">  </span><span class="c1">// this doesn&#39;t</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>I wonder if this difference is because of the implementation difference between early-bound and late-bound? I'm also curious if this difference is a compiler implementation detail or is a language rule.</p>



<a name="206024300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024300">(Aug 05 2020 at 13:53)</a>:</h4>
<p>I'm....a bit surprised by that result</p>



<a name="206024324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024324">(Aug 05 2020 at 13:53)</a>:</h4>
<p>oh, I guess I'm not</p>



<a name="206024343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024343">(Aug 05 2020 at 13:53)</a>:</h4>
<p>what's happening is that, in the first case, we are able to resolve to <code>&lt;_ as Ms&gt;::ms(1)</code></p>



<a name="206024355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024355">(Aug 05 2020 at 13:53)</a>:</h4>
<p>i.e., we don't have to know which <em>self type</em> it is to know <em>which trait</em> it is</p>



<a name="206024360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024360">(Aug 05 2020 at 13:54)</a>:</h4>
<p>then later the type falls back to <code>i32</code></p>



<a name="206024402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024402">(Aug 05 2020 at 13:54)</a>:</h4>
<p>in the second case, I imagine <code>abs</code> is an inherent method</p>



<a name="206024416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024416">(Aug 05 2020 at 13:54)</a>:</h4>
<p>so we would have to resolve to <code>i32::abs</code> or <code>i64::abs</code> and that's ambiguous</p>



<a name="206024459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024459">(Aug 05 2020 at 13:54)</a>:</h4>
<p>this is on that borderline between 'language spec' and 'compiler impl' -- we haven't totally specified our method reoslution algorithm (or much anything else)</p>



<a name="206024473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024473">(Aug 05 2020 at 13:54)</a>:</h4>
<p>I can certainly imagine implementing a smarter resolution algorithm in the future</p>



<a name="206024510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024510">(Aug 05 2020 at 13:55)</a>:</h4>
<p>(I've toyed with designs for such a thing, a type checker that is able to "defer and reorder" larger amounts of its work, but I think it's a bit on the back-burner as we pursue chalk first)</p>



<a name="206024536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Resolving%20result%20differences/near/206024536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Resolving.20result.20differences.html#206024536">(Aug 05 2020 at 13:55)</a>:</h4>
<p>Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>